<?php
require_once("../includes/config.inc.php");
validate_admin();
$id = $_REQUEST['id'];
if($_POST)
{
	@extract($_POST);
	// Edit Code
	$noerror=true;
	if(isFieldDuplicate($tableName='tbl_category',$fieldName='name',$filedValue=$name,$autoIdName='id',$autoIdValue=$id,$isNullAllowed=false)) 
	{	
		$_SESSION['sessMsg'] = " Sorry, this Category ".$name." already exists. Please choose a different Category. ";
		$noerror=false;
	}
	if($noerror)
	{	
		if($id)
		{
			$sqlEdit = " update tbl_category set
			name = '$name'
			where id ='$id'";
			executeQuery($sqlEdit);
			
			$_SESSION['sessMsg'] = "Category Detail Edited Successfully. ";
			header("location:categoryManager.php");
			exit();
		}
		else
		{
			// Add Code
			$sqlPA = " insert into tbl_category 
			(
				name,	
				status
			)
			values
			(
				'$name',
				'1'
			)
			";
			executeQuery($sqlPA );			
			$_SESSION['sessMsg'] = " New Category Added Successfully. ";
			header("location:categoryManager.php");
			exit();
		}
	}		
}
			
if($id)
{
	$sqlPD = " select * from tbl_category where id = '$id' ";
	$resPD = executeQuery($sqlPD);
	if($rowPD = mysql_fetch_array($resPD))
	{
		@extract($rowPD);
	}
}
?>